/**
 * 注册路由
 */

import React, { useState, useEffect } from 'react';
import { Button, InputItem, List, Radio, WhiteSpace, WingBlank } from 'antd-mobile';
import Logo from '../../components/login/logo'
import { login } from '../../api/index'
import {connect} from 'react-redux'
function Login(props) {

  const [param, setparam] = useState()
  const handleChange = (key, value) => {
    setparam({ ...param, [key]: value })    //这种方式更新对象很方便！！
  }

  const handleLogin = (e) => {
    console.log(param);
    login(param).then((result) => {
      props.dispatch({ type: "User_Login", data: result })
      props.history.push("/main")
    }).catch((err) => {
      alert(err)
    });
  }

  return (
    <div>
      <Button type="primary">硅谷招聘</Button>
      {/* <Logo /> */}
      <WhiteSpace />
      <List>
        <InputItem onChange={v => handleChange("username", v)}>用户名: </InputItem>
        <InputItem type="password" onChange={v => handleChange("password", v)}>密　码: </InputItem>
      </List>
      <WhiteSpace />
      <Button type="primary" onClick={handleLogin}>登陆</Button>
      <Button onClick={e => props.history.push("/register")}>注册</Button>
    </div>
  );
}

export default connect()(Login)
